package com.example.design.filter.filter;


import com.example.design.DateUtils;
import com.example.design.filter.ScheduleShiftFilter;
import com.example.design.filter.context.ScheduleContext;
import com.example.design.filter.context.ScheduleTag;
import com.example.design.filter.context.ScheduleUser;
import com.example.design.filter.enums.ScheduleTagEnum;

import java.util.Date;
import java.util.Optional;

/**
 * 不上晚班标签
 */
public class NoNightTagFilter implements ScheduleShiftFilter {

    public static final ScheduleShiftFilter instance = new NoNightTagFilter();

    @Override
    public boolean filter(ScheduleContext context, ScheduleUser user) {
        Date date = DateUtils.localDate2Date(context.getScheduleDate());
        Optional<ScheduleTag> noNightTag = user.getTags().stream()
                .filter(tag -> tag.valid(ScheduleTagEnum.NO_NIGHT, date))
                .findFirst();
        return !noNightTag.isPresent();
    }

}
